import LogFactory from "log/LogFactory";
import DrpSetting from "./DrpSetting";
import {SALE} from "./constant";
import DataStorage from "global/DataStorage";

const log = LogFactory.getLog("DrpSettingHandler");

/**
 * 进销存页面设置处理器
 */
class DrpSettingHandler {
    private static readonly KEY: string = "drpSetting";
    private static readonly instance = new DrpSettingHandler();
    private static readonly store = new DataStorage<DrpSetting>() ;
    private constructor() {
    }
    public static getInstance(): DrpSettingHandler {
        return this.instance;
    }
    public async setConfig(config: DrpSetting) {
        log.debug("设置配置: ",config);
        DrpSettingHandler.store.saveData(DrpSettingHandler.KEY,config) ;
    }
    public getConfig(): DrpSetting {
        return DrpSettingHandler.store.findData(DrpSettingHandler.KEY) ?? this.getDefaultConfig() ;
    }
    private getDefaultConfig(): DrpSetting {
        return {partPageSize: 10,defaultOdoType: SALE,defaultClient: "",defaultEngine: "",defaultProvider: "",defaultPartGroup: "",username: "admin"} ;
    }
}

export default DrpSettingHandler;